﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace WebApp
{
    public partial class UpPwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //调用母版页对象
            //this.txtSNa.Text = ((Label)this.Master.FindControl("lblUserName")).Text;
        }

        protected void btnYes_Click(object sender, EventArgs e)
        {
            
             try
            {
                string strCn = "server=pc.hstc.cn;database=dhd2014112138;uid=2014112138;pwd=19960516";
                SqlConnection conn = new SqlConnection(strCn);
                conn.Open();
                string strSql = "select * from UserInfo where UserName='" + this.txtSNa.Text + "' and  Password='" + txtSPwd.Text + "'";
                SqlCommand cmd = new SqlCommand(strSql, conn);
                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
               
                if (dr.Read())
                {
                    string strCnn = "server=pc.hstc.cn;database=dhd2014112138;uid=2014112138;pwd=19960516";
                    SqlConnection con = new SqlConnection(strCnn);
                    con.Open();
                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    SqlStringBuilder.Append("UPDATE  UserInfo ");
                    SqlStringBuilder.AppendFormat("SET     Password = N'{0}'", this.txtSPwd1.Text);
                    SqlStringBuilder.AppendFormat("WHERE   (UserName = N'{0}') ", ((Label)this.Master.FindControl("lblUserName")).Text);

                    int iUpd = SqlHelper.ExecuteNonQuery(SqlStringBuilder.ToString());
                    if (iUpd > 0)
                    {
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('修改成功！现在可以用新密码登录！')", true);
                    }
                    else
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('修改失败！')", true);

                   
                }
                else
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('你非当前用户，无修改密码权限！')", true);

            }
            catch (Exception ex)
            {
                this.Label3.Text = "修改失败！具体原因："+ex.Message;
            }
            
        }

     protected void btnNew_Click(object sender, EventArgs e)
        {
            this.txtSNa.Text = "";
            this.txtSPwd.Text = "";
            this.txtSPwd1.Text = "";
            this.txtSPwd2.Text = "";

        }

     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
     {

         Session["Theme"] = this.DropDownList1.SelectedValue.ToString();
     }
     protected void Page_PreInit(object sender, EventArgs e)
     {
         if (Session["Theme"] != null)
             this.Theme = Session["Theme"].ToString();
     }
        
    }
}